package com.xywy.beautyand.ADAPTER;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xywy.beautyand.R;
import com.xywy.beautyand.ACT.QuestionDetailAct;
import com.xywy.beautyand.base.BasicAdapter;
import com.xywy.beautyand.bean.QuestionList;

public class QuestionListAdapter extends BasicAdapter<QuestionList> {
	private LayoutInflater inflater;

	public QuestionListAdapter(Context context, List<QuestionList> list) {
		super(context, list);
		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		viewholder holder;
		if(convertView==null){
			holder=new viewholder();
			convertView=inflater.inflate(R.layout.item_question, null);
			holder.is_question_replay=(TextView) convertView.findViewById(R.id.is_question_replay);
			holder.is_question_title=(TextView) convertView.findViewById(R.id.is_question_title);
			holder.app_type=(TextView) convertView.findViewById(R.id.app_type);
			holder.question_data=(TextView) convertView.findViewById(R.id.question_data);
			convertView.setTag(holder);
		}else{
			holder=(viewholder) convertView.getTag();
		}
//		if(position%2==0){
//			holder.is_question_replay.setText("未回复");
//			holder.is_question_replay.setBackgroundResource(R.drawable.question_is_replay_normal);
//		}else{
//			holder.is_question_replay.setText("已解决 ");
//			holder.is_question_replay.setBackgroundResource(R.drawable.login_button_press);
//		}
		String state=list.get(position).getState();//0未回复未解决,1已回复,2 4已过期,3已采纳已解决 
		String datestamp=list.get(position).getDatestamp();
		String title=list.get(position).getTitle();
		String art_id=list.get(position).getArt_id();
		
		if("3".equals(state)){
			holder.is_question_replay.setText("已解决 ");
		}else if("1".equals(state)){
			holder.is_question_replay.setText("已回复 ");
		}else {
			holder.is_question_replay.setText("未解决");
		}
		
		holder.is_question_title.setText(title);
		holder.question_data.setText(datestamp);
		convertView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent=new Intent(context, QuestionDetailAct.class);
				intent.putExtra("id", list.get(position).getArt_id());
				context.startActivity(intent);
			}
		});
		return convertView;
	}
   private class viewholder{
	   private TextView is_question_replay;
	   private TextView is_question_title;
	   private TextView app_type;
	   private TextView question_data;
   }
}
